package ui.activity.poscontrol;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import net.ck.hzq.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import Utils.StringUtil;
import base.BaseAct;
import base.BaseBiz;
import butterknife.BindView;
import event.HasPushEvent;
import event.HiddenOpenEvent;
import event.NetErrorEvent;
import ui.activity.poscontrol.beanmodel.ChangebankSearchDetail;
import ui.activity.poscontrol.biz.PosControlMainBiz;
import widget.dialog.ChangeBankallowDialog;
import widget.dialog.ChangeBankdeallowDialog;
import widget.dialog.MyDialog;


/**
 * 设置返现金额页面
 * Created by chenjian on 18/2/22.
 */

public class ChangeBackDetailAct extends BaseAct  {

    PosControlMainBiz biz;
    @BindView(R.id.peoplename)
    TextView peoplename;
    @BindView(R.id.peoplephone)
    TextView peoplephone;
    @BindView(R.id.oldamount)//
    TextView oldamount;
    @BindView(R.id.changeamount)
    TextView changeamount;
    @BindView(R.id.sn)
    TextView sn;
    @BindView(R.id.postype)
    TextView postype;
    @BindView(R.id.creattime)
    TextView creattime;
    @BindView(R.id.status)
    TextView status;
    @BindView(R.id.allowbtn)
    TextView allow_btn;
    @BindView(R.id.deallowbtn)
    TextView deallow_btn;
    ChangebankSearchDetail changebankDetail;

    String snNo="";
    private int msign;
    @Override
    protected void setRoot() {
        setContentView(R.layout.activity_changebackdetail);
    }

    @Override
    protected void setup() {
        biz= new PosControlMainBiz();

        snNo=getIntent().getStringExtra("sn");
        msign = getIntent().getIntExtra("sign",0);

        if(msign==0){
            setToolBar("我发起的", "");
        }else{
            setToolBar("我接收的", "");
        }
        biz.queryChangeBankRecordDetail(snNo,new BaseBiz.Callback<ChangebankSearchDetail>() {
            @Override
            public void onSuccess(ChangebankSearchDetail posMainBean) {
                peoplename.setText(  StringUtil.getFormatPriceInt(posMainBean.getRequesterName()+""));
                peoplephone.setText(  StringUtil.getFormatPriceInt(posMainBean.getRequestPhone()+""));
                sn.setText(  StringUtil.getFormatPriceInt(posMainBean.getSn()+""));
                postype.setText(  StringUtil.getFormatPriceInt(posMainBean.getCategory()+""));
                creattime.setText(  StringUtil.getFormatPriceInt(posMainBean.getCreateTime()+""));
                oldamount.setText(  StringUtil.getFormatPriceInt(posMainBean.getSourceAmount()+""));
                changeamount.setText(  StringUtil.getFormatPriceInt(posMainBean.getNewAmount()+""));

                if(msign==0) {
                    switch (posMainBean.getStatus()) {
                        case 1:
                            status.setText( "待处理");
                            status.setTextColor(getResources().getColor(R.color.blue_0ca6f0));
                            break;
                        case 2:
                            status.setText("已成功");
                            status.setTextColor(getResources().getColor(R.color.green_189633));
                            break;
                        case 3:
                            status.setText( "已拒绝");
                            status.setTextColor(getResources().getColor(R.color.red_fe3333));
                            break;
                        case 4:
                            status.setText("已过期");
                            status.setTextColor(getResources().getColor(R.color.tc_666666));
                            break;
                    }
                }else{
                    switch (posMainBean.getStatus()) {
                        case 1:
                            status.setText( "待处理");
                            status.setTextColor(getResources().getColor(R.color.blue_0ca6f0));
                            allow_btn.setVisibility(View.VISIBLE);
                            deallow_btn.setVisibility(View.VISIBLE);
                            break;
                        case 2:
                            status.setText("已同意");
                            status.setTextColor(getResources().getColor(R.color.green_189633));
                            break;
                        case 3:
                            status.setText( "已拒绝");
                            status.setTextColor(getResources().getColor(R.color.red_fe3333));
                            break;
                        case 4:
                            status.setText("已过期");
                            status.setTextColor(getResources().getColor(R.color.tc_666666));
                            break;
                    }
                }
            }

            @Override
            public void onFailure(ChangebankSearchDetail getUrlOutput) {

            }

        });
        allow_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                biz.submitChangeBackRecord(snNo,1+"",new BaseBiz.Callback<Boolean>() {
                    @Override
                    public void onSuccess(Boolean result) {
                        if(result){
                            ChangeBankallowDialog changebankDialog = new ChangeBankallowDialog(ChangeBackDetailAct.this, "", new MyDialog.DialogCallback() {
                                @Override
                                public void OnConfirm() {
                                }

                                @Override
                                public void OnConfirm1() {

                                }

                                @Override
                                public void OnCancel() {

                                }
                            });
                            deallow_btn.setEnabled(false);
                            allow_btn.setEnabled(false);
                            changebankDialog.show();
                            EventBus.getDefault().post(new HasPushEvent(1, "", ""));
                        }


                    }

                    @Override
                    public void onFailure(Boolean result) {

                    }

                });
            }
        });
        deallow_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                biz.submitChangeBackRecord(snNo,2+"",new BaseBiz.Callback<Boolean>() {
                    @Override
                    public void onSuccess(Boolean result) {
                        if(result){
                            ChangeBankdeallowDialog changebankDialog = new ChangeBankdeallowDialog(ChangeBackDetailAct.this, "", new MyDialog.DialogCallback() {
                                @Override
                                public void OnConfirm() {
                                }

                                @Override
                                public void OnConfirm1() {

                                }

                                @Override
                                public void OnCancel() {

                                }
                            });
                            deallow_btn.setEnabled(false);
                            allow_btn.setEnabled(false);
                            changebankDialog.show();
                            EventBus.getDefault().post(new HasPushEvent(1, "", ""));
                        }
                    }

                    @Override
                    public void onFailure(Boolean result) {

                    }

                });
            }
        });
    }


    @Override
    protected void init(@Nullable Bundle savedInstanceState) {


    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void onNetErrorEvent(NetErrorEvent event) {
        super.onNetErrorEvent(event);
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        biz.onDestory();
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refrshdata(HiddenOpenEvent event) {
      finish();

    }

}
